<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output
	encoding="UTF-8"
/>

<xsl:include href="announce.xsl"/>

<xsl:template match="/page">
	<html>
		<head>
			<title>
				<xsl:choose>
					<xsl:when test="/page/content/current-view/message/@type = 'single-message'">
						<xsl:value-of select="/page/content/current-view/message/title/text()" disable-output-escaping="yes"/>
					</xsl:when>
					<xsl:when test="/page/content/current-view/group-keyword">
						<xsl:text>Все про </xsl:text>
						<xsl:value-of select="/page/content/current-view/group-keyword/text()" disable-output-escaping="yes"/>
						<xsl:text> на perl6.ru</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="/page/manifest/title/text()"/>

						<xsl:if test="/page/content/month-view">
							<xsl:text> &#8212; </xsl:text>
							<xsl:call-template name="month-name">
								<xsl:with-param name="month" select="/page/content/month-view/@month"/>
							</xsl:call-template>
							<xsl:text> </xsl:text>
							<xsl:value-of select="/page/content/month-view/@year"/>
						</xsl:if>
					</xsl:otherwise>
				</xsl:choose>
			</title>
			<link rel="alternate" type="application/rss+xml" title="RSS" href="http://perl6.ru/rss/" />
			<link href="http://www.google.com/uds/css/gsearch.css" type="text/css" rel="stylesheet" />
			<link rel="stylesheet" type="text/css" href="/css/main.css" />
			<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=ABQIAAAAJadMwmjbuh6bv7kRfp40HRSJO9VWnqzrUhsVBKxWgpVTVCB7GxSs0pNGX-YlNus64YeXf1dtr6pbXQ" type="text/javascript"></script>
		</head>
		<body>
			<!--div id="language-selector" style="line-height: 150%">
				<a href="http://ru.langs.ru/">in English</a>
				<br />
				<a href="http://langs.ru/">по-русски</a>
			</div-->
			<xsl:if test="/page/manifest/uri/text() = '/'">
				<div id="rss-link">
					<a href="/rss/">RSS</a>
				</div>
			</xsl:if>
			<div class="top">
				<xsl:choose>
					<xsl:when test="/page/manifest/uri/text() = '/'">
						<xsl:value-of select="/page/manifest/title/text()"/>
						<!--small>
							<small> &#160;&#160;v.&#160;</small>
							<xsl:value-of select="/page/manifest/message-counter/text()"/>
						</small-->
					</xsl:when>
					<xsl:when test="/page/content/month-view">
						<a href="/">
							<xsl:value-of select="/page/manifest/title/text()"/>
						</a>
						<xsl:text> / </xsl:text>
						<xsl:call-template name="show-month-title"/>
					</xsl:when>
					<xsl:when test="/page/content/current-view/group-keyword">
						<a href="/">
							<xsl:value-of select="/page/manifest/title/text()"/>
						</a>
						<xsl:text> / все про </xsl:text>
						<xsl:value-of select="/page/content/current-view/group-keyword/text()" disable-output-escaping="yes"/>
					</xsl:when>
					<xsl:otherwise>
						<a href="/">
							<xsl:value-of select="/page/manifest/title/text()"/>
						</a>
					</xsl:otherwise>
				</xsl:choose>
			</div>

<!--div style="padding: 10px 0; background: white; margin: 10px 0">
	<div style="background: #376ffe; padding: 10px; color: white; text-align: center">
		<div>Первый российский воркшоп о современном состоянии перла «Perl сегодня»</div>
		<div style="font-size: 200%; margin: 20px 0">Russian Perl workshop&#8212;2007 ‘Perl today’</div>
		<div>Москва. 20-е числа октября.</div>
		<div><a style="color: white; font-size: 150%; margin: 10px" href="http://perlrussia.ru/">perlrussia.ru</a></div>
	</div>
</div-->

<!--div style="padding: 10px 0; background: white; margin: 10px 0">
	<table width="90%" align="center" style="margin-top: 4em">
		<tr>
			<td>
				<a href="http://2008.perlrussia.ru/"><img src="http://perlrussia.ru/img/yapcru2008.gif" width="486" height="159" border="0" style="border:0" /></a>
			</td>
			<td style="padding-top: 140px; padding-left: 10px">
				<div style="font-size: 260%">Конференция про Perl</div>
				<div style="margin-top: 0.3em; font-size: 160%">17—18 мая 2008, Москва</div>
				<div style="margin-top: 1em; padding-right: 2em; line-height: 130%">Название «<a href="http://2008.perlrussia.ru/">May Perl</a>» — игра слов. Основная тема воркшопа — рассказать и услышать про то, что <i>может</i> Perl и где он <i>может</i> быть использован.</div>
			</td>
		</tr>
	</table>
</div-->
			<xsl:choose>
				<xsl:when test="/page/manifest/uri/text() = '/'">
					<xsl:apply-templates select="/page/content" mode="first"/>
					<xsl:call-template name="main-announces"/>
					<xsl:apply-templates select="/page/content" mode="rest"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="/page/content"/>
				</xsl:otherwise>
			</xsl:choose>

			
			<div class="footer">
				<xsl:text>2003&#8212;</xsl:text>
				<xsl:value-of select="/page/manifest/year/text()"/>
				<br />
				<a href="http://www.shitov.ru/">Андрей Шитов</a> (<a href="mailto:andy@shitov.ru">andy@shitov.ru</a>)
			</div>
		</body>
	</html>
</xsl:template>

<xsl:template match="/page/content" mode="first">
	<div class="content" style="padding-bottom: 0">
		<xsl:apply-templates select="main-view/message[1]"/>
	</div>
</xsl:template>

<xsl:template match="/page/content" mode="rest">
	<div class="content">
		<xsl:apply-templates select="main-view/message[position() &gt; 1]"/>
		<xsl:apply-templates select="main-view/keyword-map"/>
		<xsl:apply-templates select="tag-cloud"/>
		<xsl:apply-templates select="month-calendar"/>


		<xsl:if test="/page/manifest/uri/text() != '/'">
			<div class="google-search">
				<xsl:if test="/page/content/month-view">
					<xsl:call-template name="month-navigator"/>
				</xsl:if>

				<xsl:call-template name="google-search"/>
			</div>
		</xsl:if>
	</div>
</xsl:template>

<xsl:template match="/page/content">
	<div class="content">
		<xsl:apply-templates/>


		<xsl:if test="/page/manifest/uri/text() != '/'">
			<div class="google-search">
				<xsl:if test="/page/content/month-view">
					<xsl:call-template name="month-navigator"/>
				</xsl:if>

				<xsl:call-template name="google-search"/>
			</div>
		</xsl:if>
	</div>
</xsl:template>

<xsl:template match="group-keyword"/>

<xsl:template match="message">
	<div class="message">
		<xsl:variable name="site">
			<xsl:choose>
				<xsl:when test="title/@site_id = 2">ru.langs.ru</xsl:when>
				<xsl:otherwise>perl6.ru</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<h1>
			<xsl:choose>
				<xsl:when test="../keyword-map">
					<a href="/{@uri}/">
						<xsl:value-of select="title/text()" disable-output-escaping="yes"/>
					</a>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="title/text()" disable-output-escaping="yes"/>
				</xsl:otherwise>
			</xsl:choose>
		</h1>

		<xsl:value-of select="content/text() | content/*" disable-output-escaping="yes"/>

		<xsl:choose>
			<xsl:when test="keywords/item">
				<p class="keywords">
					<xsl:for-each select="keywords/item">
						<a href="/{@uri}/">
							<xsl:value-of select="text()" disable-output-escaping="yes"/>
						</a>
						<xsl:if test="position() != last()">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
					<xsl:text>&#160;&#8212; </xsl:text>
					<xsl:call-template name="message-date"/>
				</p>
			</xsl:when>
			<xsl:when test="../keyword-map">
				<p class="keywords">
					<xsl:for-each select="../keyword-map/item[@message-id = current()/@id]">
						<xsl:choose>
							<xsl:when test="@uri = /page/content/current-view/group-keyword/@uri">
								<b>
									<xsl:value-of select="/page/manifest/keyword-list/item[@uri = current()/@uri]/text()" disable-output-escaping="yes"/>
								</b>
							</xsl:when>
							<xsl:otherwise>
								<a href="/{@uri}/">
									<xsl:value-of select="/page/manifest/keyword-list/item[@uri = current()/@uri]/text()" disable-output-escaping="yes"/>
								</a>
							</xsl:otherwise>
						</xsl:choose>
						<xsl:choose>
							<xsl:when test="position() != last()">
								<xsl:text>, </xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>&#160;&#8212; </xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
					<xsl:call-template name="message-date"/>
				</p>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="message-date"/>
			</xsl:otherwise>
		</xsl:choose>
	</div>
</xsl:template>

<xsl:template name="message-date">
	<span class="date">
		<xsl:value-of select="@day"/>
		<xsl:text>&#160;</xsl:text>
		<xsl:choose>
			<xsl:when test="@month = 1">января</xsl:when>
			<xsl:when test="@month = 2">февраля</xsl:when>
			<xsl:when test="@month = 3">марта</xsl:when>
			<xsl:when test="@month = 4">апреля</xsl:when>
			<xsl:when test="@month = 5">мая</xsl:when>
			<xsl:when test="@month = 6">июня</xsl:when>
			<xsl:when test="@month = 7">июля</xsl:when>
			<xsl:when test="@month = 8">августа</xsl:when>
			<xsl:when test="@month = 9">сентября</xsl:when>
			<xsl:when test="@month = 10">октября</xsl:when>
			<xsl:when test="@month = 11">ноября</xsl:when>
			<xsl:when test="@month = 12">декабря</xsl:when>
		</xsl:choose>
		<xsl:text>&#160;</xsl:text>
		<xsl:value-of select="@year"/>
	</span>
</xsl:template>

<xsl:template name="show-month-title">
	<xsl:call-template name="month-name">
		<xsl:with-param name="month" select="/page/content/month-view/@month"/>
	</xsl:call-template>

	<xsl:text> </xsl:text>
	<xsl:value-of select="/page/content/month-view/@year"/>
</xsl:template>

<xsl:template match="content/tag-cloud">
	<div class="common-navigation">
		<p>Дальнейшая навигация&#160;&#8212; по&#160;ключевым словам, через поиск или по&#160;календарю.</p>
		<xsl:variable name="max" select="@max"/>
		<xsl:variable name="min" select="@min"/>
			
		<div class="tag-cloud">
			<xsl:for-each select="item">
				<span class="nobr">
					<a href="/{@uri}/">
						<xsl:attribute name="class">
							<xsl:text>sz</xsl:text>
							<xsl:value-of select="round (10 * (@count - $min) div $max)"/>
						</xsl:attribute>
						<xsl:value-of select="text()" disable-output-escaping="yes"/>
					</a>
					<xsl:text>&#160;&#160;</xsl:text>
				</span>
				<xsl:text> </xsl:text>
			</xsl:for-each>
		</div>

		<xsl:call-template name="google-search"/>
		
		<xsl:call-template name="month-calendar"/>

		<p style="margin-top: 3em">Сайт посвящен процессу освоения Perl&#160;6. Ни&#160;стабильного компилятора, ни&#160;окончательной спецификации шестой версии языка еще не&#160;существует, но&#160;уже сейчас с&#160;языком можно экспериментировать, пользуясь доступным инструментарием.</p>
		<p style="margin-top: 0.7em">Новые сообщения появляются по&#160;ходу моего изучения языка. Периодичность выхода ничем не&#160;оговорена, что отлично видно по&#160;календарю.</p>
	</div>
</xsl:template>

<xsl:template match="content/month-calendar"/>

<xsl:template name="month-calendar">
	<xsl:variable name="month-calendar" select="/page/content/month-calendar"/>
	<div class="calendar">
		<div>
			<b>
				<xsl:value-of select="$month-calendar/item[1]/@year"/>
				<br />
			</b>
			<xsl:for-each select="$month-calendar/item">
				<a href="/{@year}/{@month}/">
					<xsl:call-template name="month-name">
						<xsl:with-param name="month" select="@month"/>
					</xsl:call-template>
				</a>
				<br />
				<xsl:if test="@year != following-sibling::item[1]/@year">
					<xsl:text disable-output-escaping="yes">
						&lt;/div&gt;
						&lt;div&gt;
					</xsl:text>
					<b>
						<xsl:value-of select="following-sibling::item[1]/@year"/>
					</b>
					<br />
				</xsl:if>
			</xsl:for-each>
		</div>
	</div>
	<br clear="all" />
</xsl:template>

<xsl:template name="google-search">
		<div id="searchcontrol"/> 
		<script language="Javascript" type="text/javascript">
		//<![CDATA[
			var searchControl = new GSearchControl();
			var webSearch = new GwebSearch();
			webSearch.setSiteRestriction ("perl6.ru")
			options = new GsearcherOptions(); 
			options.setExpandMode (GSearchControl.EXPAND_MODE_OPEN); 
			searchControl.addSearcher (webSearch, options);
			searchControl.setResultSetSize (GSearch.LARGE_RESULTSET);
			searchControl.setLinkTarget (GSearch.LINK_TARGET_SELF);
			searchControl.draw (document.getElementById ("searchcontrol"));
		//]]>
		</script>
</xsl:template>

<xsl:template name="month-name">
	<xsl:param name="month"/>

	<xsl:choose>
		<xsl:when test="$month = 1">январь</xsl:when>
		<xsl:when test="$month = 2">февраль</xsl:when>
		<xsl:when test="$month = 3">март</xsl:when>
		<xsl:when test="$month = 4">апрель</xsl:when>
		<xsl:when test="$month = 5">май</xsl:when>
		<xsl:when test="$month = 6">июнь</xsl:when>
		<xsl:when test="$month = 7">июль</xsl:when>
		<xsl:when test="$month = 8">август</xsl:when>
		<xsl:when test="$month = 9">сентябрь</xsl:when>
		<xsl:when test="$month = 10">октябрь</xsl:when>
		<xsl:when test="$month = 11">ноябрь</xsl:when>
		<xsl:when test="$month = 12">декабрь</xsl:when>
	</xsl:choose>
</xsl:template>

<xsl:template name="month-navigator">
	<p>
		<xsl:variable name="current-month" select="/page/content/month-calendar/item[/page/content/month-view/@year = @year and @month = /page/content/month-view/@month]"/>
		
		<xsl:variable name="prev" select="/page/content/month-calendar/item[generate-id (preceding-sibling::item[1]) = generate-id ($current-month)]"/>
		<xsl:variable name="next" select="/page/content/month-calendar/item[generate-id (following-sibling::item[1]) = generate-id ($current-month)]"/>

		<xsl:if test="$prev">
			<a href="/{$prev/@year}/{$prev/@month}/">
				<xsl:attribute name="title">
					<xsl:call-template name="month-name">
						<xsl:with-param name="month" select="$prev/@month"/>
					</xsl:call-template>
					<xsl:text> </xsl:text>
					<xsl:value-of select="$prev/@year"/>
				</xsl:attribute>
				<xsl:text>&#8592;</xsl:text>
			</a>
			<xsl:text>&#160; </xsl:text>
		</xsl:if>

		<xsl:call-template name="month-name">
			<xsl:with-param name="month" select="/page/content/month-view/@month"/>
		</xsl:call-template>
		<xsl:text>&#160;</xsl:text>
		<xsl:value-of select="/page/content/month-view/@year"/>

		<xsl:if test="$next">
			<xsl:text>&#160; </xsl:text>
			<a href="/{$next/@year}/{$next/@month}/">
				<xsl:attribute name="title">
					<xsl:call-template name="month-name">
						<xsl:with-param name="month" select="$next/@month"/>
					</xsl:call-template>
					<xsl:text> </xsl:text>
					<xsl:value-of select="$next/@year"/>
				</xsl:attribute>
				<xsl:text>&#8594;</xsl:text>
			</a>
		</xsl:if>
	</p>
	<br />
</xsl:template>

</xsl:stylesheet>
